#!/usr/bin/env python
'''
program tries to fit curves for different L for KT scaling for magnetisation
'''
from __future__ import division

import common
import os
import matplotlib.pyplot
import math

path = os.path.join('..', '..', 'results', 'triang', 'J_-1.0')

B = common.choice(path)

lList = common.choice(os.path.join(path, B))

a = 1.2
b = 0.105 / 2

Tc = 0.1 


for tL in lList:
    L = int(tL.replace("L_", ''))
    lPath = os.path.join(path, B, tL, "OP")  
    tList, mList = common.sorted_list(lPath)
    
    x = tList
    
    y = []
    
    for i, value in enumerate(mList):
        y += [ value ]
    
    for i in xrange(0, len(tList) -1):
        if tList[i] < Tc and tList[i + 1 ] < Tc:
            TcIndex = i 
    
    x = []
    y = []
    for i, T in enumerate(tList):
        if T < Tc:
            x += [ (1 / L) * math.exp(a * math.pow( (Tc - T) / Tc, -0.5 )) ]
            y += [ mList[i] * L**b ]
    
    matplotlib.pyplot.plot(x, y, '*', label = "$L = %i$"%L)

matplotlib.pyplot.xscale('log')
matplotlib.pyplot.legend()
matplotlib.pyplot.show()
                            
    
    
        